﻿using System;
using System.Linq;

using Microsoft.WowAddonStudio.Lua.AST;
using Microsoft.WowAddonStudio.Lua.Model;
using Microsoft.WowAddonStudio.Lua.Support;

using Variable=Microsoft.WowAddonStudio.Lua.Model.Variable;

namespace Microsoft.WowAddonStudio.Lua.Adapters
{
    /// <summary>
    /// Adds documentation for the <see cref="ForLoop"/> nodes in the AST.
    /// </summary>
    public class ForLoopDocumentationAdapter : DocumentationAdapter<ForLoop>
    {
        public override void AddDocumentation(DocumentationScope documentationScope, ForLoop node)
        {
            base.AddDocumentation(documentationScope, node);

            var bodyScope = node.InnerScope as DocumentationScope;
            if (bodyScope != null)
            {
                var iteratorVariables = node.GetIdentifiers().Select(identifier => DeclarationFactory.CreateDeclaration<Variable>(identifier, true));
                bodyScope.AddRange(iteratorVariables.Cast<Declaration>());
            }
        }
    }
}
